package com.dingding.transfer.stamper.handler;

import com.alibaba.fastjson.JSONObject;
import com.dingding.transfer.stamper.constant.EventType;
import com.dingding.transfer.stamper.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wangxiyuan
 * @description 审批实例处理器 审批流程开始和结束的时候会触发
 * @createDate 2021/3/31 16:30
 **/
@Slf4j
public class TaskInstanceHandler implements EventHandler{
    @Override
    public boolean support(String eventType) {
        if (EventType.APPROVE_INSTANCE.getEventType().equals(eventType)) {
            return true;
        }
        return false;
    }

    @Override
    public boolean handle(JSONObject jsonObject) {
        try {
            TaskInstanceProcessorRegistry taskInstanceProcessorRegistry = SpringContextUtil.getBean(TaskInstanceProcessorRegistry.class);
            taskInstanceProcessorRegistry.handleInstance(jsonObject);
        } catch (Exception e) {
            log.error("任务审批实例处理器回调出现错误{}",e.getMessage());
            return false;
        }
        return  true;
    }
}
